/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exiftool;

/**
 *
 * @author chris
 */
public class photosTable extends javax.swing.table.AbstractTableModel {

    java.util.concurrent.ConcurrentSkipListSet<exifheader.ImageExif> photoList;
    exifheader.ImageExif[] photoArray; //Array of ImageExif objects
    java.lang.String[] columnNames;

    /**
     *
     */
    public photosTable() {
        super();
        columnNames = new java.lang.String[]{"Name", "Make", "Model", "Date",
                    "Time", "Latitude", "Longitude"};
    }

    public void loadImages(java.io.File myDir) {
        //java.io.File myDir = new java.io.File("C:/scan/20-11-09");
        if (myDir.exists() && myDir.isDirectory()) {
            java.io.File[] photoFiles =
                    myDir.listFiles(new exiftool.resources.photoFileFilter());

            photoList =
                    new java.util.concurrent.ConcurrentSkipListSet<exifheader.ImageExif>();
            try {
                for (int i = 0; i < photoFiles.length; i++) {
                    //ImageExif myExif = new exifheader.ImageExif(photoFiles[i]);
//                    imgExif = new exifheader.ImageExif(photoFiles[i]);
                    photoList.add(new exifheader.ImageExif(photoFiles[i]));
                }
                //myExif.showExif();
            } catch (java.lang.Exception e) {
                return;
            }
            photoArray = photoList.toArray(new exifheader.ImageExif[0]);

            //photoList.
        }
    }

    public int getRowCount() {
        if (photoList == null) {
            return 0;
        }
        return photoList.size();
        //return 4;
    }

    public int getColumnCount() {
        return 7;
    }

    public Object getValueAt(int Row, int Col) {
        switch (Col) {
            case 0:
                return photoArray[Row].getName();
            case 1:
                return photoArray[Row].getMake();
            case 2:
                return photoArray[Row].getModel();
            case 3:
                return toDate(photoArray[Row].getDate());
            case 4:
                return toTime(photoArray[Row].getDate());
            case 5:
                return photoArray[Row].getLatitude();
            case 6:
                return photoArray[Row].getLongitude();
        }
        //photoList.
        return null;
    }

    @Override
    public String getColumnName(int Col) {
        return columnNames[Col];
    }

    @Override
    public boolean isCellEditable(int Row, int Col) {
        if (Col > 2) {
            return true;
        }
        return false;
    }

    private java.lang.String toDate(java.util.Date date) {
        if (date == null) {
            return null;
        }
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(date);

    }

    private java.lang.String toTime(java.util.Date date) {
        if (date == null) {
            return null;
        }
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("HH:mm:ss");
        return formatter.format(date);

    }
}
